const { Sequelize } = require('sequelize');

// 方法 1: 传递一个连接 URI
// const sequelize = new Sequelize('sqlite::memory:') // Sqlite 示例
// const sequelize = new Sequelize('postgres://user:pass@example.com:5432/dbname') // Postgres 示例

// 方法 2: 分别传递参数 (sqlite)
// const sequelize = new Sequelize({
//   dialect: 'sqlite',
//   storage: 'path/to/database.sqlite'
// });

// 方法 3: 分别传递参数 (其它数据库)
const sequelize = new Sequelize('master', 'sa', 'Kdvssqlserver123', {
  host: '10.11.3.90',
  port: 1433,
  dialect: 'mssql', /* 选择 'mysql' | 'mariadb' | 'postgres' | 'mssql' 其一 */
});

;(async function() {
  try {
    await sequelize.authenticate();
    console.log('Connection has been established successfully.');
    await sequelize.query('SELECT * from spt_monitor').then(([results]) => { 
      console.log(results)
    })
    // 关闭连接
    sequelize.close()
  } catch (error) {
    console.error('Unable to connect to the database:', error);
  }
})()